home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.1 / Assembler / subroutines / openlibs.asm < prev    next >
Encoding:
Assembly Source File  |  1992-08-27  |  2.8 KB  |  81 lines

  1. ;
  2. ; Copyright (c) 1988 Commodore-Amiga, Inc.
  3. ;
  4. ; Executables based on this information may be used in software
  5. ; for Commodore Amiga computers.  All other rights reserved.
  6. ;
  7. ; This information is provided "as is"; no warranties are made.
  8. ; All use is at your own risk, and no liability or responsibility is assumed.
  9. ;
  10.  
  11.         XREF    _LVOOpenLibrary,_LVOCloseLibrary
  12.  
  13. ;==============================================================================
  14. ; Success = OpenLibs( libtable )
  15. ;   d0             a0
  16. ;
  17. ; Opens all libraries referenced in the library table.  Table format is:-
  18. ;
  19. ;    version,name,offset        (all are signed words)
  20. ;
  21. ; Version is the version number required for this library.
  22. ; Name is the offset from libtable to the required library name.
  23. ; Offset is the offset (from global pointer a5) of where to store lib ptr.
  24. ; List is terminated by a version number of -1
  25. ;==============================================================================
  26. OpenLibs    movem.l    a2-a3/a6,-(sp)
  27.         movea.l    SysLib(a5),a6        using exec library
  28.         movea.l    a0,a2            save working libtable ptr
  29.         movea.l    a0,a3            a3 used to calculate name addr
  30.  
  31. 10$        moveq.l    #0,d0            get the version
  32.         move.w    (a2)+,d0
  33.         bmi.s    LibsOpened        return TRUE
  34.         move.w    (a2)+,d1        get offset to name
  35.         lea.l    0(a3,d1.w),a1        addr of name in a1
  36.         jsr    _LVOOpenLibrary(a6)    open the lib
  37.         move.w    (a2)+,d1        offset to store at
  38.         move.l    d0,0(a5,d1.w)        save in global table
  39.         bne.s    10$            OK, go for the next
  40. LibsOpened    movem.l    (sp)+,a2-a3/a6        could return 0 if failed above
  41.         rts        
  42.  
  43. ;==============================================================================
  44. ; CloseLibs( libtable )
  45. ;        a0
  46. ;
  47. ; Closes all libraries opened by OpenLibs() providing the pointer to that
  48. ; library (as stored in global table) is non zero, (the open succeeded).
  49. ;==============================================================================
  50. CloseLibs    movem.l    a2/a6,-(sp)
  51.         movea.l    SysLib(a5),a6        using exec library
  52.         movea.l    a0,a2            save libtable pointer
  53.  
  54. 10$        tst.w    (a2)+            end of list ?
  55.         bmi.s    LibsClosed        yes, quit now
  56.         move.l    (a2)+,d0        offset to lower word
  57.         move.l    0(a5,d0.w),d0        get lib pointer
  58.         beq.s    LibsClosed        that's it, this one failed
  59.         movea.l    d0,a1
  60.         jsr    _LVOCloseLibrary(a6)    close this library
  61.         bra.s    10$            and go for the next
  62. LibsClosed    movem.l    (sp)+,a2/a6
  63.         rts
  64.  
  65. ;==============================================================================
  66. ; An example list of libraries that would be sent to the OpenLibraries routine.
  67. ; IntLib, GfxLib and DosLib would all be members defined in the global struct.
  68. ;==============================================================================
  69. Libraries    DC.W    33,IntName-Libraries,IntLib
  70.         DC.W    33,GfxName-Libraries,GfxLib
  71.         DC.W    33,DosName-Libraries,DosLib
  72.         DC.W    -1
  73. IntName        DC.B    'intuition.library',0
  74.         CNOP    0,2
  75. GfxName        DC.B    'graphics.library',0
  76.         CNOP    0,2
  77. DosName        DC.B    'dos.library',0
  78.         CNOP    0,2
  79.  
  80.         END
  81.